package GUI;

import java.awt.Color;
import java.awt.LayoutManager;

import javax.crypto.SealedObject;
import javax.swing.JPanel;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

import logic.Message;
import java.awt.GridLayout;

public class Manager_Menu extends JPanel {

	private Client_GUI parent;
	
	private JButton btnActivityReport;
	private JButton btnLoanReports;
	private JButton btnLateReturnsReport;
	private boolean isHidden = true;
	
	public Manager_Menu(final Client_GUI parent) {
		this.parent = parent;
		this.setBackground(Color.white);

		this.setSize(parent.MENU_WIDTH,parent.MENU_HEIGHT);
		setLayout(null);
		
		JPanel panel = new JPanel();
		panel.setBackground(Color.white);
		panel.setBounds(5, 5, 140, 350);
		add(panel);
		panel.setLayout(new GridLayout(0, 1, 0, 0));
		
		JButton btnHome = new JButton("Home");
		panel.add(btnHome);
		
		JButton btnViewMember = new JButton("Search Member");
		panel.add(btnViewMember);
		
		JButton btnViewWorker = new JButton("Search Worker");
		panel.add(btnViewWorker);
		
		JButton btnSearchBook = new JButton("Search Book");
		panel.add(btnSearchBook);
		
		JButton btnSearchOrder = new JButton("Search Order");
		panel.add(btnSearchOrder);
		
		JButton btnSearchLoan = new JButton("Search Loan");
		panel.add(btnSearchLoan);
		
		JButton btnViewReports = new JButton("View Reports");
		panel.add(btnViewReports);
		
		btnActivityReport = new JButton("Activity Report");
		panel.add(btnActivityReport);
		
		btnLoanReports = new JButton("Loan Reports");
		panel.add(btnLoanReports);
		
		btnLateReturnsReport = new JButton("Late Returns Report");
		panel.add(btnLateReturnsReport);
		btnLateReturnsReport.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				Reports topaint = new Reports(parent,Message.LATE_RETURN_REPORT_REQUEST);
				parent.RepaintMain(topaint);
			}
		});
		btnLoanReports.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				
				Reports topaint = new Reports(parent,Message.LOAN_REPORT_REQUEST);
				parent.RepaintMain(topaint);
			}
		});
		btnActivityReport.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				int action = Message.ACTIVITY_REPORT_REQUEST;
				
				//TODO call activity report
				
			}
		});
		btnViewReports.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				SetReportsVisibility(!isHidden);
			}
		});
		btnSearchLoan.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				SearchLoan topaint = new SearchLoan(parent,SearchLoan.SEARCH_LOAN,null);
				parent.RepaintMain(topaint);
			}
		});
		btnSearchOrder.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				SearchOrder topaint = new SearchOrder(parent);
				parent.RepaintMain(topaint);
			}
		});
		btnSearchBook.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				SearchBook topaint = new SearchBook(parent, SearchBook.SEARCH, null);
				parent.RepaintMain(topaint);
			}
		});
		btnViewWorker.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				SearchWorker topaint = new SearchWorker(parent, null);
				parent.RepaintMain(topaint);
			}
		});
		btnViewMember.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				SearchMember topaint = new SearchMember(parent, SearchMember.SEARCH, null);
				parent.RepaintMain(topaint);
				
			}
		});
		btnHome.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				Home home = new Home(parent,parent.client.publicMessages);
				parent.RepaintMain(home);
			}
		});
		
		SetReportsVisibility(false);
	}
	
	
	/**
	 * Set the Reports button group's visiblity
	 * @param value - visibilty value to set
	 */
	private void SetReportsVisibility(boolean value){
		btnActivityReport.setVisible(value);
		btnLoanReports.setVisible(value);
		btnLateReturnsReport.setVisible(value);
		isHidden = value;
	}


}
